package com.example.lss.news.dao;


import com.example.lss.news.bean.User;
import com.example.lss.news.bean.UserBean;

import java.util.List;

import io.realm.Realm;
import io.realm.RealmResults;

public class NewsDao {
    public List<User> show() {
        Realm realm = Realm.getDefaultInstance();
        RealmResults<User> all = realm.where(User.class).findAll();
        List<User> featureBeans = realm.copyFromRealm(all);
        realm.close();
        return featureBeans;
    }

    public List<User> showone(String phone) {
        Realm realm = Realm.getDefaultInstance();
        RealmResults<User> all = realm.where(User.class).equalTo("phone", phone).findAll();
        List<User> featureBeans = realm.copyFromRealm(all);
        realm.close();
        return featureBeans;
    }


    public void add(User bean) {
        Realm realm = Realm.getDefaultInstance();
        realm.beginTransaction();
        realm.insertOrUpdate(bean);
        realm.commitTransaction();
        realm.close();
    }


}
